﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.IO;

public partial class Manager_ProdAddNew : System.Web.UI.PageEx
{
    private string strPageCode = "P0000C";
    private string strLoginResult = string.Empty;
    private string strProdCode = string.Empty;
    private int iSelectId = 0;
    private string strSelectLang = "CN";
    protected void Page_Load(object sender, EventArgs e)
    {
        string strSelectLang1 = Convert.ToString(Request.QueryString["Lang"]);
        strSelectLang = string.IsNullOrEmpty(strSelectLang1) ? strSelectLang : strSelectLang1;
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        btnCopyProd.Visible = ddlCorpProdName.Visible = strSelectLang.CompareTo("CN") == 0;
        int.TryParse(Convert.ToString(Request.QueryString["ProdId"]), out iSelectId);
        if (strSelectLang.CompareTo("EN") == 0)
        {
            lblProdName.Text += "(*)";
            lblProdProperty.Text += "(*)";
            txtKeywords.Label += "(*)";
            txtDescription.Label += "(*)";
            ContentPanel1.Title += "(*)";
            txtProdCode.Readonly = true;
        }
        if (!Page.IsPostBack)
        {
            ViewState["SelectLang"] = strSelectLang;
            btnReset.OnClientClick = sfObject.GetResetReference();
            DataBinds();
        }
    }
    protected void DataBinds()
    {
        #region 属性添加操作
        //DataSet _ds = DalEx.ParamsExtEx.Select();
        //Model.DbParamsEx dbParamsEx = null;
        //FineUI.Label lblObject = new FineUI.Label();
        //FineUI.TextArea taObject = new FineUI.TextArea();
        //FineUI.TextBox txObject = new FineUI.TextBox();
        //FineUI.HtmlEditor heObject = new FineUI.HtmlEditor();
        //FineUI.DropDownList ddlObject = new FineUI.DropDownList();
        //FineUI.CheckBoxList cboxObject = new FineUI.CheckBoxList();
        //FineUI.RadioButtonList rbtObject = new FineUI.RadioButtonList();
        //FineUI.Panel pnlObject = new FineUI.Panel();
        //if (SqlHelper.HasRow(_ds))
        //{
        //    cpProperty.BodyPadding = "5px 0px 0px 5px";
        //    cpProperty.ShowHeader = true;
        //    cpProperty.ShowBorder = true;
        //}
        //foreach (DataRow dr in _ds.Tables[0].Rows)
        //{
        //    dbParamsEx = new Model.DbParamsEx(dr);

        //    pnlObject = new FineUI.Panel();
        //    pnlObject.CssClass = "x-form-item datecontainer";
        //    pnlObject.ShowBorder = false;
        //    pnlObject.ShowHeader = false;
        //    pnlObject.Layout = FineUI.Layout.Table;

        //    lblObject = new FineUI.Label();
        //    lblObject.Width = 95;
        //    lblObject.Text = dbParamsEx.PName + "：";
        //    lblObject.CssClass = "inline";
        //    lblObject.ShowLabel = false;
        //    pnlObject.Items.Add(lblObject);

        //    switch (dbParamsEx.PFieldType)
        //    {
        //        case "TextBox":
        //            txObject = new FineUI.TextBox();
        //            txObject.Width = 200;
        //            txObject.ShowLabel = true;
        //            txObject.ID = dbParamsEx.PName;
        //            txObject.Label = dbParamsEx.PName;
        //            txObject.Text = dbParamsEx.PTextDefaultValue;
        //            txObject.EmptyText = dbParamsEx.PRemarks;
        //            txObject.MaxLength = 255;
        //            pnlObject.Items.Add(txObject);
        //            break;
        //        case "TextArea":
        //            taObject = new FineUI.TextArea();
        //            taObject.ID = dbParamsEx.PName;
        //            taObject.Width = 600;
        //            taObject.Height = 80;
        //            taObject.Label = dbParamsEx.PName;
        //            taObject.Text = dbParamsEx.PTextDefaultValue;
        //            taObject.EmptyText = dbParamsEx.PRemarks;
        //            pnlObject.Items.Add(taObject);
        //            break;
        //        case "DropDownList":
        //            ddlObject = new FineUI.DropDownList();
        //            ddlObject.ID = dbParamsEx.PName;
        //            ddlObject.Width = 200 ;
        //            foreach (string strValue in dbParamsEx.PTextDefaultValue.Split('|'))
        //                ddlObject.Items.Add(new FineUI.ListItem(strValue, strValue));
        //            ddlObject.SelectedValue = dbParamsEx.PSelectTextValue;
        //            pnlObject.Items.Add(ddlObject);
        //            break;
        //        case "RatioButton":
        //            rbtObject = new FineUI.RadioButtonList();
        //            rbtObject.ID = dbParamsEx.PName;
        //            foreach (string strValue in dbParamsEx.PTextDefaultValue.Split('|'))
        //                rbtObject.Items.Add(new FineUI.RadioItem(strValue, strValue));
        //            rbtObject.ColumnNumber = 5;
        //            rbtObject.SelectedValue = dbParamsEx.PSelectTextValue;
        //            pnlObject.Items.Add(rbtObject);
        //            break;
        //        case "CheckBox":
        //            cboxObject = new FineUI.CheckBoxList();
        //            cboxObject.ID = dbParamsEx.PName;
        //            foreach (string strValue in dbParamsEx.PTextDefaultValue.Split('|'))
        //                cboxObject.Items.Add(new FineUI.CheckItem(strValue, strValue));
        //            cboxObject.SelectedValueArray = dbParamsEx.PSelectTextValue.Split('|');
        //            cboxObject.ColumnNumber = 5;
        //            pnlObject.Items.Add(cboxObject);
        //            break;
        //        case "HtmlEditor":
        //            heObject = new FineUI.HtmlEditor();
        //            heObject.ID = dbParamsEx.PName;
        //            heObject.Width = 600;
        //            heObject.Label = dbParamsEx.PName;
        //            heObject.Text = dbParamsEx.PTextDefaultValue;
        //            pnlObject.Items.Add(heObject);
        //            break;
        //    }
        //    cpProperty.Controls.Add(pnlObject);
        //}
        #endregion
        strSelectLang = Convert.ToString(ViewState["SelectLang"]);
        List<Model.DbClass> lstClass = new List<Model.DbClass>();
        DalEx.DbClassEx.GetClassList(0, " and cType=1", ref lstClass, strSelectLang);
        ddlProdClass.DataSource = lstClass;
        ddlProdClass.DataValueField = "CId";
        ddlProdClass.DataTextField = "CName";
        ddlProdClass.DataSimulateTreeLevelField = "CLevel";
        ddlProdClass.DataBind();
        ddlProdClass.Items.Insert(0, new FineUI.ListItem("请选择产品类别", string.Empty));
        //////////////////////////
        DataSet ds = DalEx.DbProductsEx.Select();
        ddlCorpProdName.DataSource = ds;
        ddlCorpProdName.DataTextField = "PName";
        ddlCorpProdName.DataValueField = "PCode";
        ddlCorpProdName.DataBind();
        ddlCorpProdName.Items.Insert(0, new FineUI.ListItem("请选择要拷贝的产品", "0"));
        if (iSelectId > 0)//如果产品ID>0时绑定产品属性
        {
            Hashtable htAttr1 = null;
            Hashtable htAttr2 = null;
            Model.DbProducts products = DalEx.DbProductsEx.Select(iSelectId, strSelectLang);
            if (products != null)
            {
                hfProdId.Text = products.PId.ToString();
                hfProdCode.Text = products.PCode;
                hfProdClassId.Text = products.PClassId.ToString();
                txtProdCode.Text = products.PCode;
                txtProdName.Text = products.PName;
                ddlProdClass.SelectedValue = products.PClassId.ToString();
                txtProdOrder.Text = products.POrder.ToString();
                txtProdHits.Text = products.PHits.ToString();
                txtProdInstr.Text = products.PShortInstr;
                txtKeywords.Text = products.PKeywords;
                txtDescription.Text = products.PDescription;
                txtMarketPrice.Text = products.PMarketPrice;
                txtUserPrice.Text = products.PUserPrice;
                txtWeight.Text = products.PWeight;
                txtStoreAmount.Text = products.PStoreAmount.ToString();

                fuProdImages.EmptyText = "图片不修改，保留空！";
                fuProdImages.Required = false;

                List<string> lstSelectValue = new List<string>();
                if (products.PStatus == 1)
                    lstSelectValue.Add("1");
                if (products.PIsHot == 1)
                    lstSelectValue.Add("2");
                if (products.PIsNews == 1)
                    lstSelectValue.Add("3");
                cboxProdExt.SelectedValueArray = lstSelectValue.ToArray();
                
                UEditor1.Value = HttpUtility.HtmlDecode(products.PNote);
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int iProdOrder = 0;
        int iProdHits = 0;
        int iProdClass=0;
        int iStoreAmount = 0;
        strSelectLang = Convert.ToString(ViewState["SelectLang"]);
        short sProdStatus = 0, sProdIsHot = 0, sProdIsNew = 0;
        if (ddlProdClass.SelectedIndex == 0)
        {
            FineUI.Alert.Show("请选择产品类别！", FineUI.MessageBoxIcon.Warning);
        }
        else
        {
            string strSelectProdId = hfProdId.Text.Trim();
            int.TryParse(strSelectProdId, out iSelectId);
            string strProdeName = txtProdName.Text.Trim();
            string strProdCode = txtProdCode.Text.Trim();
            string strClassId = ddlProdClass.SelectedValue.Trim();
            int.TryParse(strClassId,out iProdClass);
            string strMarketPrice = txtMarketPrice.Text.Trim();
            string strUserPrice = txtUserPrice.Text.Trim();
            string strKeywords = txtKeywords.Text.Trim();
            string strDescription = txtDescription.Text.Trim();
            string strProdInstr = txtProdInstr.Text.Trim();
            string strProdNote = HttpUtility.HtmlEncode(UEditor1.Value);
            string strProdOrder = txtProdOrder.Text.Trim();
            int.TryParse(strProdOrder, out iProdOrder);
            string strProdHits = txtProdHits.Text.Trim();
            int.TryParse(strProdHits, out iProdHits);
            string strStoreAmount = SqlHelper.String(txtStoreAmount.Text);
            int.TryParse(strStoreAmount, out iStoreAmount);
            string strWeight = SqlHelper.String(txtWeight.Text);
            #region 基本属性
            ArrayList lstResult = new ArrayList();
            Hashtable htPropertyName = DalEx.ParamsExtEx.GetProdParams();
            string strFromValues = string.Empty;
            int iIndexTemp = htPropertyName.Count;
            foreach (string strkey in htPropertyName.Keys)
            {
                iIndexTemp--;
                strFromValues = SqlHelper.String(Request.Form["pp_" + strkey]);
                strFromValues = strFromValues.Replace(',', '|');
                GetArrtValue(strFromValues, strkey, strProdCode, 3, iIndexTemp, ref lstResult);
            }
            #region 备份
            //string strYS = txtColor.Text.Trim();
            //string strCZ = txtData.Text.Trim();
            //string strCanD = txtMadeFrom.Text.Trim();
            //string strCD = txtCD.Text.Trim();
            //string strKD = txtKD.Text.Trim();
            //string strGD = txtGD.Text.Trim();
            //string strYG = txtYG.Text.Trim();
            //string strZC = txtZS.Text.Trim();
            //switch (strSelectLang)
            //{
            //    case "EN":
            //        GetArrtValue(strYS, "Color", strProdCode, 2, 1, ref lstResult);
            //        GetArrtValue(strCZ, "Material", strProdCode, 2, 2, ref lstResult);
            //        GetArrtValue(strCanD, "Original", strProdCode, 2, 3, ref lstResult);
            //        GetArrtValue(strCD, "L", strProdCode, 3, 1, ref lstResult);
            //        GetArrtValue(strKD, "W", strProdCode, 3, 2, ref lstResult);
            //        GetArrtValue(strGD, "H", strProdCode, 3, 3, ref lstResult);
            //        GetArrtValue(strYG, "Seat High", strProdCode, 3, 2, ref lstResult);
            //        GetArrtValue(strZC, "Seat Deep", strProdCode, 3, 5, ref lstResult);
            //        break;
            //    default:
            //        GetArrtValue(strYS, "颜色", strProdCode, 2, 1, ref lstResult);
            //        GetArrtValue(strCZ, "材质", strProdCode, 2, 2, ref lstResult);
            //        GetArrtValue(strCanD, "产地", strProdCode, 2, 3, ref lstResult);
            //        GetArrtValue(strCD, "长", strProdCode, 3, 1, ref lstResult);
            //        GetArrtValue(strKD, "宽", strProdCode, 3, 2, ref lstResult);
            //        GetArrtValue(strGD, "高", strProdCode, 3, 3, ref lstResult);
            //        GetArrtValue(strYG, "椅高", strProdCode, 3, 2, ref lstResult);
            //        GetArrtValue(strZC, "座深", strProdCode, 3, 5, ref lstResult);  
            //        break;
            //}  
            #endregion
            #endregion
            //foreach (FineUI.CheckItem item in cboxProdExt.Items)
            //{
            //    switch (item.Text)
            //    {
            //        case "显示":
            //            sProdStatus = Convert.ToInt16(item.Selected);
            //            break;
            //        case "热销":
            //            sProdIsHot = Convert.ToInt16(item.Selected);
            //            break;
            //        case "新品":
            //            sProdIsNew = Convert.ToInt16(item.Selected);
            //            break;
            //    }
            //}
            string[] strProdExt = cboxProdExt.SelectedValueArray;
            foreach (string strValue in strProdExt)
            {
                switch (strValue)
                { 
                    case "1":
                        sProdStatus = 1;
                        break;
                    case "2":
                        sProdIsHot = 1;
                        break;
                    case "3":
                        sProdIsNew = 1;
                        break;
                }
            }
            #region 上传图片
            string strErrorMsg = string.Empty;
            string strProdImages = WebBase.Comm.GetFilePath(fuProdImages, Server.MapPath("~/upload/products/" + iProdClass + "/"), ResolveUrl("~/upload/products/" + iProdClass + "/"), true, true, 0.6, AllowUpFileExt, ref strErrorMsg);// GetFilePath(fuProdImages, iProdClass, AllowUpFileExt, ref strErrorMsg);
            #endregion
            Model.DbProducts products = new Model.DbProducts();
            products.PId = iSelectId;
            products.PName = strProdeName;
            products.PCode = strProdCode;
            products.PClassId = iProdClass;
            products.PAddTime = DateTime.Now;
            products.PKeywords = strKeywords;
            products.PDescription = strDescription;
            products.PShortInstr = strProdInstr;
            products.POrder = iProdOrder;
            products.PHits = iProdHits;
            products.PStatus = sProdStatus;
            products.PIsHot = sProdIsHot;
            products.PIsNews = sProdIsNew;
            products.PUserPrice = strUserPrice;
            products.PMarketPrice = strMarketPrice;
            products.PNote = strProdNote;
            products.PDefaultImg = strProdImages;
            products.PWeight = strWeight;
            products.PStoreAmount = iStoreAmount;
            //string filename = System.IO.Path.GetFileName(strProdImages);//
            products.PSmallDefaultImg = strProdImages.Replace(ResolveUrl("~/upload/products/" + iProdClass + "/"), ResolveUrl("~/upload/products/" + iProdClass + "/") + "small_");// ResolveUrl("~/upload/products/" + iProdClass + "/") + "small_" + filename;
            products.PBigDefaultImg = strProdImages.Replace(ResolveUrl("~/upload/products/" + iProdClass + "/"), ResolveUrl("~/upload/products/" + iProdClass + "/") + "big_");
            int iResult = 0;
            string strResult = string.Empty;
            switch (strSelectLang)
            {
                case "EN":
                    Model.DbEnProducts dbEnProducts = new Model.DbEnProducts();
                    dbEnProducts.PCode = products.PCode;
                    dbEnProducts.PEnDescription = products.PDescription;
                    dbEnProducts.PEnKeywords = products.PKeywords;
                    dbEnProducts.PEnName = products.PName;
                    dbEnProducts.PEnNote = products.PNote;
                    dbEnProducts.PEnShortInstr = products.PShortInstr;
                    dbEnProducts.PEnAddTime = DateTime.Now;
                    iResult = DalEx.DbProductsEx.InsertEn(dbEnProducts, lstResult);
                    strResult = iResult > 0 ? "英文版内容编辑成功！" : "英文版内容编辑失败！";
                    break;
                default:
                    iResult = DalEx.DbProductsEx.InsertEx(products, lstResult, ref strResult);
                    break;
            }
            if (iResult > 0)
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Information);
                if (iSelectId == 0)
                {
                    sfObject.Reset();
                }
            }
            else
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Warning);
            }
        }

    }
    protected void txtProdCode_TextChanged(object sender, EventArgs e)
    {
        string strSelectProdId = hfProdId.Text.Trim();
        int.TryParse(strSelectProdId, out iSelectId);
        string strProdCode = SqlHelper.String(txtProdCode.Text.Trim());
        Model.DbProducts products = DalEx.DbProductsEx.GetModel(strProdCode);
        if (products != null && products.PId != iSelectId)
        {
            FineUI.Alert.Show("产品编号已经存在！", FineUI.MessageBoxIcon.Warning);
            txtProdCode.Text = string.Empty;
        }
    }
    protected void btnUpProdImageOther_Click(object sender, EventArgs e)
    {       
        strProdCode = txtProdCode.Text.Trim();
        ViewState["ProdCode"] = strProdCode;
        if (string.IsNullOrEmpty(strProdCode) || ddlProdClass.SelectedIndex==0)
        {
            FineUI.Alert.Show("请确定产品编号及产品类型已选择！", FineUI.MessageBoxIcon.Warning);
        }
        else
        {
            txtProdCode.Readonly = true;
            hfProdCode.Text = strProdCode;
            hfProdClassId.Text = ddlProdClass.SelectedValue;
            ddlProdClass.Readonly = true;
            //sfImage.Reset();
            winProdImage.Hidden = false;
            LoadProdImage(strProdCode);
        }
    }
    protected void btnSaveImage_Click(object sender, EventArgs e)
    {
        int iImageOrder = 99;
        int iProdClassId = 0;
        string strProdCode1 = SqlHelper.String(Convert.ToString(ViewState["ProdCode"]));
        string strImageName = SqlHelper.String(txtImageName.Text.Trim());
        string strEnImageName = SqlHelper.String(txtEnImageName.Text.Trim());
        string strImageOrder = txtImageOrder.Text.Trim();
        int.TryParse(strImageOrder, out iImageOrder);  
        int.TryParse(Convert.ToString(ddlProdClass.SelectedValue),out iProdClassId);

        string strImageResult = string.Empty;
        string strImagePath = WebBase.Comm.GetFilePath(fuProdImage1, Server.MapPath("~/upload/products/" + iProdClassId + "/"), ResolveUrl("~/upload/products/" + iProdClassId + "/"), true,true, 0.6, AllowUpFileExt, ref strImageResult);//GetFilePath(fuProdImage1, iProdClassId, AllowUpFileExt, ref strImageResult);
        Model.DbProductsEx dbProductsEx = new Model.DbProductsEx();
        dbProductsEx.PeProdCode = strProdCode1;
        dbProductsEx.PeType = 1;
        dbProductsEx.PeValue = strImagePath;
        string filename = System.IO.Path.GetFileName(strImagePath);//
        dbProductsEx.PeValue0 = ResolveUrl("~/upload/products/" + iProdClassId + "/") + "big_" + filename;
        dbProductsEx.PeValue1 = ResolveUrl("~/upload/products/" + iProdClassId + "/") + "small_" + filename;
        dbProductsEx.PeOrder = iImageOrder;
        dbProductsEx.PeName = strImageName;
        dbProductsEx.PeEnName = strEnImageName;

        if (Dal.DbProductsExDal.Insert(dbProductsEx) > 0)
        {
            LoadProdImage(strProdCode1);
            FineUI.Alert.Show("产品图片上传成功！", FineUI.MessageBoxIcon.Information);
            sfImage.Reset();
        }
        else
        {
            FineUI.Alert.Show("产品图片上传失败！", FineUI.MessageBoxIcon.Error);
        }
    }
    protected void btnCopyProd_Click(object sender, EventArgs e)
    {
        Hashtable htAttr1 = null;
        Hashtable htAttr2 =null;
        if (ddlCorpProdName.SelectedIndex == 0)
        {
            FineUI.Alert.Show("请选择要拷贝的产品！", FineUI.MessageBoxIcon.Warning);
        }
        else
        {
            string strProdCode = ddlCorpProdName.SelectedValue.Trim();
            Model.DbProducts products = DalEx.DbProductsEx.GetModel(strProdCode);
            if (products != null)
            {
                txtProdName.Text = products.PName;
                ddlProdClass.SelectedValue = products.PClassId.ToString();
                txtProdOrder.Text = products.POrder.ToString();
                txtProdHits.Text = products.PHits.ToString();
                txtProdInstr.Text = products.PShortInstr;
                txtKeywords.Text = products.PKeywords;
                txtDescription.Text = products.PDescription;
                txtMarketPrice.Text = products.PMarketPrice;
                txtUserPrice.Text = products.PUserPrice;

                List<string> lstSelectValue = new List<string>();
                if (products.PStatus == 1)
                    lstSelectValue.Add("1");
                if (products.PIsHot == 1)
                    lstSelectValue.Add("2");
                if (products.PIsNews == 1)
                    lstSelectValue.Add("3");
                cboxProdExt.SelectedValueArray = lstSelectValue.ToArray();

                //htAttr1 = DalEx.DbProductsEx.GetHashTableProdEx(products.PCode, 2, strSelectLang);
                //if (htAttr1.ContainsKey("颜色"))
                //    txtColor.Text = htAttr1["颜色"].ToString();
                //if (htAttr1.ContainsKey("材质"))
                //    txtData.Text = htAttr1["材质"].ToString();
                //if (htAttr1.ContainsKey("产地"))
                //    txtMadeFrom.Text = htAttr1["产地"].ToString();
                //htAttr2 = DalEx.DbProductsEx.GetHashTableProdEx(products.PCode, 3, strSelectLang);
                //if (htAttr2.ContainsKey("长"))
                //    txtCD.Text = htAttr2["长"].ToString();
                //if (htAttr2.ContainsKey("宽"))
                //    txtKD.Text = htAttr2["宽"].ToString();
                //if (htAttr2.ContainsKey("高"))
                //    txtGD.Text = htAttr2["高"].ToString();
                //if (htAttr2.ContainsKey("座位高"))
                //    txtYG.Text = htAttr2["座位高"].ToString();
                //if (htAttr2.ContainsKey("座深"))
                //    txtZS.Text = htAttr2["座深"].ToString();
            }
        }
    }
    protected void winProdImage_Close(object sender, EventArgs e)
    {
        sfImage.Hidden = true;
    }
    private void LoadProdImage(string strProdCode)
    {
        DataSet ds = Dal.DbProductsExDal.Select(" and peProdCode='" + strProdCode + "' and peType=1");
        gridImage.DataSource = ds;
        gridImage.DataBind();
    }
    private string GetFilePath(FineUI.FileUpload fileUpload,int ClassId, string strFileExt,ref string strResult)
    {
        string fileName = string.Empty;
        if (fileUpload.HasFile)
        {
            fileName = fileUpload.ShortFileName;
            fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
            fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
            //检查目录是否存在，不存在则创建
            if (!Directory.Exists(Server.MapPath("~/upload/products/" + ClassId+"/")))
                Directory.CreateDirectory(Server.MapPath("~/upload/products/" + ClassId + "/"));
            //文件保存
            fileUpload.SaveAs(Server.MapPath("~/upload/products/" + ClassId + "/" + fileName));
            fileName = ResolveUrl("~/upload/products/" + ClassId + "/" + fileName);
        }
        return fileName;
    }
    private void GetArrtValue(string strValue,string strText,string strProdCode,short sPeType,int iIndex, ref ArrayList lstResult)
    {
        Model.DbProductsEx dbProductsEx = null;
        if (!string.IsNullOrEmpty(strValue))
        {
            dbProductsEx = new Model.DbProductsEx();
            dbProductsEx.PeProdCode = strProdCode;
            dbProductsEx.PeType = sPeType;//基本属性
            dbProductsEx.PeName = strText;
            dbProductsEx.PeValue = strValue;
            dbProductsEx.PeOrder = iIndex;
            dbProductsEx.PeLang = strSelectLang;
            lstResult.Add(dbProductsEx);
        }
    }
    protected void gridImage_RowCommand(object sender, FineUI.GridCommandEventArgs e)
    {
        strProdCode = Convert.ToString(ViewState["ProdCode"]);
        int iSelectId = 0;
        Dictionary<int, Dictionary<int, string>> modifiedDict = gridImage.GetModifiedDict();
        string strCommand = e.CommandName;
        int iResult = 0;
        string strResult = string.Empty;
        if (!string.IsNullOrEmpty(strCommand))
        {
            int iSelectIndexId = e.RowIndex;
            string strSelectId = gridImage.Rows[iSelectIndexId].DataKeys[0].ToString();
            Int32.TryParse(strSelectId, out iSelectId);

            switch (strCommand)
            {
                case "Delete":
                    iResult = DalEx.DbProductsEx.ExDelete(" and PeId=" + iSelectId);
                    break;
                case "Modify":
                    if (modifiedDict.ContainsKey(iSelectIndexId))
                    {
                        Dictionary<int, string> rowDict = modifiedDict[iSelectIndexId];
                        Model.DbProductsEx dbProductsEx = Dal.DbProductsExDal.Select(iSelectId);
                        if (rowDict.ContainsKey(0))
                        {
                            dbProductsEx.PeName = SqlHelper.String(rowDict[0]);
                        } if (rowDict.ContainsKey(1))
                        {
                            dbProductsEx.PeEnName = SqlHelper.String(rowDict[1]);
                        }
                        iResult = Dal.DbProductsExDal.Update(dbProductsEx);
                    }
                    else
                    {
                        FineUI.Alert.Show("您没有修改任何信息不能保存！", FineUI.MessageBoxIcon.Warning);
                    }
                    break;
            }
            if (iResult > 0)
            {
                FineUI.Alert.Show("数据操作成功！", FineUI.MessageBoxIcon.Information);
                //DataBinds();
                LoadProdImage(strProdCode);
            }
            else
            {
                FineUI.Alert.Show("数据操作失败！", FineUI.MessageBoxIcon.Warning);
            }
        }
    }
}
